const UserModel = require('../../models/UserModel');
// 用户服务
const UserService = {
  login: async ({ username, password }) => {
    return await UserModel.find({ username, password });
  },
  register: async ({ username, password, gender, introduction, avatar, role }) => {
    if (!username || !password) {
      return false;
    }
    return await UserModel.create({ username, password, gender, introduction, avatar, role });
  },
  // 根据id 修改
  edit: async (_id, data) => {
    return await UserModel.updateOne({ _id }, { ...data });
  },
  list: async () => {
    return await UserModel.find({}, ['username', 'gender', 'introduction', 'avatar', 'role']);
  },
  // 查询单个
  findOneUser: async data => {
    return await UserModel.findOne({ ...data });
  },
  // 删除
  delete: async _id => {
    return await UserModel.deleteOne({ _id });
  },
};

module.exports = UserService;
